<?php

namespace app\admin\controller;

/**
* 
*/
class Member extends Base
{
 	//会员列表
 	public function list_l(){
 		$member=model('Member')->order('id','desc')->paginate(10);
 		$viewData=[
 			'member'=>$member
 		];
 		$this->assign($viewData);
 		return view();
 	}



 	//会员添加
 	public function add(){
 		if(request()->isAjax()){
 			$data=[
 				'username'=>input('post.username'),
 				'password'=>input('post.password'),
 				'conpass'=>input('post.conpass'),
 				'nickname'=>input('post.nickname'),
 				'email'=>input('post.email'),
 			];
 			$result=model('Member')->add($data);
 			if($result==1){
 				$this->success('添加成功','admin/member/list_l');
 			}else{
 				$this->error($result);
 			}
 		}

 		return view();
 	}

 	//会员编辑
 	public function edit(){
 		if(request()->isAjax()){
 			$data=[
 				'id'=>input('post.id'),
 				'username'=>input('post.username'),
 				'oldpassword'=>input('post.oldpassword'),
 				'newpassword'=>input('post.newpassword'),
 				'newconpass'=>input('post.newconpass'), 				
 				'nickname'=>input('post.nickname'),
 				'email'=>input('post.email'),
 			];
 			$result=model('Member')->edit($data);
 			if($result==1){
 				$this->success('修改成功！','admin/member/list_l');
 			}else{
 				$this->error($result);
 			}
 		}
 		$memberInfo=model('Member')->find(input(input('get.id')));
 		$viewData=[
 			'memberInfo'=>$memberInfo
 		];
 		$this->assign($viewData);
 		return view();
 	}
 	//会员删除
 	public function del(){
 		if(request()->isAjax()){
 			$data=['id'=>input('post.id')];
 		$memberInfo=model('Member')->with('content')->find($data['id']);
 		$result=$memberInfo->together('content')->delete();
 		if($result==1){
 			$this->success('删除成功！','admin/member/list_l');
 		}else{
 			$this->error($result);
 		}
 		}

 	}
}






